/* eslint-disable prettier/prettier */
import { BasicColumn, FormSchema } from '@/components/Table';
import { defHttp } from '@/utils/http/axios';
import { ifShow, ifDescription } from '@/utils/schema_util'
/**
 * 表格列配置
 */
export const tableColumns: BasicColumn[] = [
  {
    title: '部门名称',
    dataIndex: 'name',
    component: 'Input',
    componentProps: {
      placeholder: "请输入部门名称",
    }
  },
  {
    title: '唯一编码',
    dataIndex: 'code',
    component: 'Input',
    componentProps: {
      placeholder: "请输入唯一编码",
    }
  },
  {
    title: '排序',
    dataIndex: 'sort',
    component: 'InputNumber',
    componentProps: {
      placeholder: "请输入排序",
    }
  },
  {
    title: '是否启用',
    dataIndex: 'enabled',
    component: 'ApiDict',
    componentProps: {
      code: "yes_no",
      dataType: "number",
      placeholder: "请选择是否启用",
    }
  },
  {
    title: '部门负责人',
    dataIndex: 'leaderIds',
    component: 'ApiSelect',
    componentProps: {
      api: "/sys/user/select",
      mode: "multiple",
      immediate: true,
      params: {"labelKey":"realName","valueKey":"id"},
      placeholder: "请选择部门负责人",
    }
  },
  {
    title: '分管领导',
    dataIndex: 'mainLeaderId',
    component: 'ApiSelect',
    componentProps: {
      api: "/sys/user/select",
      immediate: true,
      params: {"labelKey":"realName","valueKey":"id"},
      placeholder: "请选择分管领导",
    }
  },
  {
    title: '备注',
    dataIndex: 'remark',
    component: 'InputTextArea',
    componentProps: {
      showCount: true,
      placeholder: "请输入备注",
    }
  },
  {
    title: '操作',
    dataIndex: '__ACTION__',
  },
];
/**
 * 搜索表单配置
 */
export const searchFormSchemas: FormSchema[] = [
];

/**
 * 新增、编辑表单配置
 */
export const formSchemas: FormSchema[] = [
  {
    field: 'id',
    label: '部门ID',
    component: 'Input',
    show: false,
    description: false,
    componentProps: {
      type: "hidden",
      placeholder: "请输入部门ID",
    } as any,
    required: false,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":1,"editHide":0,"listHide":1,"viewHide":1,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"Input_type":"hidden"}
      return ifShow(data,ext);
    },
  },
  {
    field: 'parentId',
    label: '所属上级',
    component: 'ApiTreeSelect',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"ApiTreeSelect_api":"/sys/dept/tree","ApiTreeSelect_immediate":true,"ApiTreeSelect_replaceFields":{"title":"name","value":"id","key":"id","children":"children"}}
      return ifDescription(data,ext);
    },
    defaultValue: "0",
    componentProps: {
      cacheKey: "sys:dept:tree",
      api: (params) => {
        return defHttp.post({ url: '/sys/dept/tree', params });
      },
      immediate: true,
      placeholder: "请选择所属上级",
      labelField: "name",
      valueField: "id",
    } as any,
    required: false,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"ApiTreeSelect_api":"/sys/dept/tree","ApiTreeSelect_immediate":true,"ApiTreeSelect_replaceFields":{"title":"name","value":"id","key":"id","children":"children"}}
      return ifShow(data,ext);
    },
  },
  {
    field: 'name',
    label: '部门名称',
    component: 'Input',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0}
      return ifDescription(data,ext);
    },
    componentProps: {
      placeholder: "请输入部门名称",
    } as any,
    required: true,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0}
      return ifShow(data,ext);
    },
  },
  {
    field: 'code',
    label: '唯一编码',
    component: 'Input',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0}
      return ifDescription(data,ext);
    },
    componentProps: {
      placeholder: "请输入唯一编码",
    } as any,
    required: true,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0}
      return ifShow(data,ext);
    },
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0}
      return ifDescription(data,ext);
    },
    defaultValue: "999",
    componentProps: {
      placeholder: "请输入排序",
    } as any,
    required: true,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0}
      return ifShow(data,ext);
    },
  },
  {
    field: 'enabled',
    label: '是否启用',
    component: 'ApiDict',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false}
      return ifDescription(data,ext);
    },
    defaultValue: 1,
    componentProps: {
      code: "yes_no",
      dataType: "number",
      placeholder: "请选择是否启用",
    } as any,
    required: true,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false}
      return ifShow(data,ext);
    },
  },
  {
    field: 'leaderIds',
    label: '部门负责人',
    component: 'ApiSelect',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"ApiSelect_api":"/sys/user/select","ApiSelect_mode":"multiple","ApiSelect_immediate":true,"ApiSelect_params":{"labelKey":"realName","valueKey":"id"},"popupContainerInBody":false,"ApiTreeSelect_api":"/sys/dept/tree","ApiTreeSelect_immediate":true,"ApiTreeSelect_replaceFields":{"title":"name","value":"id","key":"id","children":"children"},"ApiTreeSelect_params":{"labelKey":"name"}}
      return ifDescription(data,ext);
    },
    componentProps: {
      cacheKey: "sys:user:select",
      api: (params) => {
        return defHttp.post({ url: '/sys/user/select', params });
      },
      mode: "multiple",
      immediate: true,
      params: {"labelKey":"realName","valueKey":"id"},
      placeholder: "请选择部门负责人",
    } as any,
    required: false,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"ApiSelect_api":"/sys/user/select","ApiSelect_mode":"multiple","ApiSelect_immediate":true,"ApiSelect_params":{"labelKey":"realName","valueKey":"id"},"popupContainerInBody":false,"ApiTreeSelect_api":"/sys/dept/tree","ApiTreeSelect_immediate":true,"ApiTreeSelect_replaceFields":{"title":"name","value":"id","key":"id","children":"children"},"ApiTreeSelect_params":{"labelKey":"name"}}
      return ifShow(data,ext);
    },
  },
  {
    field: 'mainLeaderId',
    label: '分管领导',
    component: 'ApiSelect',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"ApiSelect_api":"/sys/user/select","ApiSelect_immediate":true,"ApiSelect_params":{"labelKey":"realName","valueKey":"id"},"popupContainerInBody":false}
      return ifDescription(data,ext);
    },
    componentProps: {
      cacheKey: "sys:user:select",
      api: (params) => {
        return defHttp.post({ url: '/sys/user/select', params });
      },
      immediate: true,
      params: {"labelKey":"realName","valueKey":"id"},
      placeholder: "请选择分管领导",
    } as any,
    required: false,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"ApiSelect_api":"/sys/user/select","ApiSelect_immediate":true,"ApiSelect_params":{"labelKey":"realName","valueKey":"id"},"popupContainerInBody":false}
      return ifShow(data,ext);
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"InputTextArea_showCount":true}
      return ifDescription(data,ext);
    },
    componentProps: {
      showCount: true,
      placeholder: "请输入备注",
    } as any,
    required: false,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"InputTextArea_showCount":true}
      return ifShow(data,ext);
    },
  },
];
